#ifndef _SKYPECOMMAND_H_
#define _SKYPECOMMAND_H_
//
#include <windows.h>
#include <tchar.h>
#include "SkypeCommWindow.h"
#include "../../Utils/String.h"
//
class SkypeCommand {
    typedef std::list<tstring> TContainer;
public:
	SkypeCommand(const TCHAR* cmd);
	~SkypeCommand();
	bool sendTo(SkypeCommWindow& skypeCommWindow);
	operator LPCTSTR() const {return _cmd;}
    static const unsigned long RESP_TIMEOUT = 500;
    static const unsigned long SEND_TO_TIMEOUT = 1500;
protected:
    class ProcessArg;
    virtual void processCommand(ProcessArg* arg);
private:
	static unsigned long _cmdCounter;
	unsigned long _cmdNo;
	TCHAR* _cmd;
    std::vector<tstring> _response;
	//
    static void __cdecl _thrProcessCommand(void* data);
    bool _findSkypeResponse(const TContainer& container, const TContainer::const_iterator& end,
                                      std::vector<tstring>& response);
    //
	SkypeCommand();
	SkypeCommand(const SkypeCommand&);
	SkypeCommand& operator = (const SkypeCommand&);
};
//
class SkypeCommand::ProcessArg {
public:
    ProcessArg(SkypeCommand& skypeCommand, SkypeCommWindow& skypeCommWindow, long cmdNo, std::vector<tstring>& skypeResponse) 
        : _skypeCommand(skypeCommand), _skypeCommWindow(skypeCommWindow), _cmdNo(cmdNo), _skypeResponse(skypeResponse) {
    }
    //
    SkypeCommand& getSkypeCommand() {
        return _skypeCommand;
    }
    //
    SkypeCommWindow& getSkypeCommWindow() {
        return _skypeCommWindow;
    }
    //
    long getCmdNo() {
        return _cmdNo;
    }
    //
    std::vector<tstring>& getSkypeResponse() {
        return _skypeResponse;
    }
private:
    SkypeCommand& _skypeCommand;
    SkypeCommWindow& _skypeCommWindow;
    long _cmdNo;
    std::vector<tstring>& _skypeResponse;
};
//
#endif
